<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 
 * Code server of 3dmb.net
 * @author chinhle
 * @date: 21/03/2013
 */
class index extends PublicController {

	public $data;
	public function __construct() {
		parent::__construct();
		
		//Initialize variable
		$this->data = array();
		$this->data['template_url'] = base_url('public').'/';
		$this->data['image_upload'] = base_url('public').'/images/upload/';
		
		//Load database
		$arr_load = array('info_model','video_model','image_model','protfolio_model');
		$this->load->model($arr_load);
		
		/**********Load all info***************/
		$this->data['firm'] = $this->info_model->get( array('id'=>4) );
		$this->data['service_a'] = $this->info_model->get( array('id'=>5) );
		$this->data['service_b'] = $this->info_model->get( array('id'=>6) );
		$this->data['contact'] = $this->info_model->get( array('id'=>7) );
		
		//Load video
		$this->data['video'] = $this->video_model->get();
		
		//Load list parent protfolio
		$this->data['protfolio']['parent'] = $this->protfolio_model->get( array('parent_id'=>0) );
		
		//Load protfolio
		$this->data['protfolio']['co'] = $this->protfolio_model->get( array('parent_id'=>42) );
		$this->data['protfolio']['ec'] = $this->protfolio_model->get( array('parent_id'=>43) );
		$this->data['protfolio']['mf'] = $this->protfolio_model->get( array('parent_id'=>44) );
		
		//Image of each protfolio
		$protfolio_child = $this->protfolio_model->get( array('parent_id !='=>0) );
		foreach($protfolio_child as $key=>$item){
			$protfolio_child[$key]['image'] = $this->image_model->get( array('fk_menu_id'=>$item['id']) );
		}
		$this->data['prot_child'] = $protfolio_child;	
		/***********End load all info************/
	}
	
	public function index() {
		//Parse view
		$this->load->view('index',$this->data);
	}
	
	/*
	 * Ajax function for get data all case
	 * */
	public function ajax_get_data(){
		if( $_POST['type'] ){
			switch ($_POST['type']){
				case 'firm':
					$view = 'firm';
					break;
				case 'service':
					$view = 'service';
					break;
				case 'protfolio':
					$view = 'protfolio';
					break;
				case 'video':
					$view = 'video';
					break;
				case 'contact':
					$view = 'contact';
					break;
				default:
					$view = null;								
			}
		}
		if($view){
			$html = $this->load->view($view,$this->data,true);
			echo json_encode( array('status'=>'ok','msg'=>$html) );
			exit;
		}
		echo json_encode( array('status'=>'error','msg'=>'') );exit;
	}
	
}
